<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        function ListNode(val, next) {
            this.val = (val===undefined ? 0 : val)
            this.next = (next===undefined ? null : next)
        }
        const h5 = new ListNode(5, null)
        const h4 = new ListNode(4, h5)
        const h3 = new ListNode(3, h4)
        const h2 = new ListNode(2, h3)
        const h1 = new ListNode(1, h2)
        // console.log(h1, h2, h3 ,h4, h5)
        var reverseList = function(head) {
            let pre = null
            
            function handle(cur) {
                if(cur) {
                    return handle(cur)
                }else{
                    return pre
                }
                console.log(cur)
                let next = cur.next
                cur.next = pre
                pre = cur
                cur = next
            }
            return handle(head)
        };
        console.log(reverseList(h1))
    </script>
</body>
</html>